﻿using GameDesigner.Displayers;
using WeifenLuo.WinFormsUI.Docking;
using GameDesigner.Source.Elements;
using GameDesigner.Source.Widgets;
using G.Model.Runtime;
using GameLibrary.Model;

namespace GameDesigner.Forms
{
    public partial class PropertyForm : DockContent
    {
        public PropertyForm()
        {
            InitializeComponent();
            ActiveObject.ObjectChangedEvent += this.OnChange;
            ActiveGame.GameChangedEvent += OnGameSelected;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
            ActiveObject.ObjectChangedEvent -= OnChange;
            ActiveGame.GameChangedEvent -= OnGameSelected;
        }
        
        private void OnGameSelected(GameDef game)
        {
            if (game == null)
            {
            this.propertyGrid1.SelectedObject = null;
            }
        }
        
        private void OnChange(object obj)
        {
            this.propertyGrid1.SelectedObject = obj;
        }
    }
}
